from django.contrib import admin

# Register your models here.
from booktest.models import BookInfo,HeroInfo

# ａｄｍｉｎ站点名称信息
admin.site.site_header = '建大书城'
# 设置页面标题
admin.site.site_title = '建大书城ＭＩＳ'
# 设置首页标语
admin.site.index_title = '建大图书馆'


# 增加关联对象
class HeroInfoStackInline(admin.StackedInline):
    model = HeroInfo
    extra = 1
# class BookInfoStackInline(admin.StackedInline):
#     model = BookInfo
#     extra = 1
class HeroInfoTabularInline(admin.TabularInline):
    model = HeroInfo
    extra = 1


# 定义装饰器，用来装饰站点显示的数据
class BookInfoAdmin(admin.ModelAdmin):
    #显示的内容
    list_display = ('id','btitle','bread','bcomment','new_pub_date','is_delete')
    # 每页显示的内容数量
    list_per_page = 2
    # 底部执行条
    actions_on_bottom = True
    # 条件查询框
    search_fields = ['btitle']

    # 详情展示内容
    # fields = ['btitle','bpub_date']
    #　详情分组展示
    fieldsets = (
        ('基本',{'fields':['btitle','bpub_date','image']}),
        ('高级',{'fields':['bcomment','bread'],
               'classes':('collapse',)
               })
    )

    # 注册关联对象类
    inlines = [HeroInfoStackInline,HeroInfoTabularInline]

#　第一种注册装饰器到站点的方式
admin.site.register(BookInfo,BookInfoAdmin)


# 第二种注册装饰器到站点的方法
@admin.register(HeroInfo)
class HeroInfoAdmin(admin.ModelAdmin):
    list_display = ('id','hname','hbook','read')
    list_per_page = 5
    actions_on_bottom = True
    # 添加过滤选项
    list_filter = ['hgender','hbook']
    # 添加搜索框
    search_fields = ['hname']
    # inlines = [BookInfoStackInline]
    # inlines = [HeroInfoTabularInline]





